package com.epro.dx.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.epro.dx.R;
import com.google.android.gms.internal.mc;
import com.weipu.common.constants.ServerConstant;
import com.weipu.common.facade.model.OrderItemModel;

/**
 * 订单列表 Adapter
 * @author  qsc255
 * @version  [版本号, 2015-1-27]
 * @see  [相关类/方法]
 * @since  [产品/模块版本]
 */
public class OrdersAdapter extends BaseAdapter
{
    
    /**
     * 上下文环境
     */
    private Context context;
    
    private List<OrderItemModel> orderlist;
    
    public OrdersAdapter(Context context, List<OrderItemModel> orderlist)
    {
        super();
        this.context = context;
        this.orderlist = orderlist;
    }
    
    @Override
    public int getCount()
    {
        
        return orderlist.size() != 0 ? orderlist.size() : 0;
    }
    
    @Override
    public Object getItem(int position)
    {
        
        return null == orderlist ? null : orderlist.get(position);
    }
    
    @Override
    public long getItemId(int position)
    {
        
        return position;
    }
    
    @Override
    public View getView(int position, View convertView, ViewGroup parent)
    {
        OrdersViewHolder ordersViewHolder;
        if (null == convertView)
        {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_orders, null);
            ordersViewHolder = new OrdersViewHolder();
            ordersViewHolder.OrderStatus = (TextView)convertView.findViewById(R.id.order_status_text);
            ordersViewHolder.OrderNumber = (TextView)convertView.findViewById(R.id.order_id_text);
            ordersViewHolder.GrandTotal = (TextView)convertView.findViewById(R.id.order_total_text);
            ordersViewHolder.OrderDate = (TextView)convertView.findViewById(R.id.order_date_text);
            convertView.setTag(ordersViewHolder);
        }
        else
        {
            ordersViewHolder = (OrdersViewHolder)convertView.getTag();
        }
        
        ordersViewHolder.OrderNumber.setText(orderlist.get(position).getOrderNumber());
        ordersViewHolder.GrandTotal.setText(context.getString(R.string.product_price1)
            + orderlist.get(position).getGrandTotal());
        ordersViewHolder.OrderDate.setText(orderlist.get(position).getOrderDate());
        
        int orderLight = Integer.parseInt(orderlist.get(position).getLight());
        
        switch (orderLight)
        {
        
            case ServerConstant.MapKey.ORDER_PENDING_PAYMENT:
                ordersViewHolder.OrderStatus.setText(ServerConstant.MapValue.ORDER_PENDING_PAYMENT);
                ordersViewHolder.OrderStatus.setTextColor(context.getResources().getColor(R.color.base_tv_1EA321));
                break;
            case ServerConstant.MapKey.ORDER_PAYMENT_RECEVIED:
                ordersViewHolder.OrderStatus.setText(ServerConstant.MapValue.ORDER_PAYMENT_RECEVIED);
                ordersViewHolder.OrderStatus.setTextColor(context.getResources().getColor(R.color.base_tv_1EA321));
                break;
            case ServerConstant.MapKey.ORDER_FULL_SHIPMENT:
                ordersViewHolder.OrderStatus.setText(ServerConstant.MapValue.ORDER_FULL_SHIPMENT);
                ordersViewHolder.OrderStatus.setTextColor(context.getResources().getColor(R.color.base_tv_1EA321));
                break;
            case ServerConstant.MapKey.ORDER_COMPLETED:
                ordersViewHolder.OrderStatus.setText(ServerConstant.MapValue.ORDER_COMPLETED);
                ordersViewHolder.OrderStatus.setTextColor(context.getResources().getColor(R.color.base_tv_1EA321));
                break;
            case ServerConstant.MapKey.ORDER_CANCEL:
                ordersViewHolder.OrderStatus.setText(ServerConstant.MapValue.ORDER_CANCEL);
                ordersViewHolder.OrderStatus.setTextColor(context.getResources().getColor(R.color.base_product_name_4F4F4F));
                break;
            default:
                break;
        
        }
        
        return convertView;
        
    }
    
    static class OrdersViewHolder
    {
        TextView OrderStatus;
        
        TextView OrderNumber;
        
        TextView GrandTotal;
        
        TextView OrderDate;
    }
    
}
